#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    string reverseWords(string s) {
        int n = s.size();
        int i = 0;

        while (i < n)
        {
            int start = i;
            while (i < n && s[i] != ' ')
            {
                i++;
            }

            int left = start, right = i - 1;
            while (left < right)
            {
                swap(s[left], s[right]);
                left++;
                right--;
            }

            while (i < n && s[i] == ' ')
            {
                i++;
            }
        }
        return s;
    }
};